<?php
require dirname(dirname(dirname(__FILE__))).'/include/db_connect.php';
include dirname(dirname(__FILE__)).'/user-manage/functions.php';
include dirname(dirname(dirname(__FILE__))).'/include/host-base.php';
session_start();
$arr = array();
for($i=1;$i<=7;$i++) {
	foreach(range('a', 'f') as $item) {
		$arr[$i][$item] = 0;
		if(isset($_POST[$item.'_'.$i]))$arr[$i][$item]=1;
	}
}


$row = getUserById($_SESSION['user_id']);
$id = $row['id'];
$student_id = addslashes($_POST['student_id']);
$department = addslashes($_POST['department']);
$grade = addslashes($_POST['grade']);
$user_real_name = addslashes($_POST['user_real_name']);
$sex = addslashes($_POST['sex']);
$phone = addslashes($_POST['phone']);
$available_time = json_encode($arr);
$is_user_on_duty = 0;
if(isset($_POST['is_user_on_duty'])&&addslashes($_POST['is_user_on_duty'])==1)$is_user_on_duty=1;


$conn = get_db_conn();
$sql = 'update user set student_id = "'.$student_id.
		'",department = "'.$department.'",grade = "'.$grade.'",user_real_name = "'.$user_real_name.
		'",sex = "'.$sex.'",phone = "'.$phone.'",available_time = \''.$available_time.'\',is_user_on_duty = '.$is_user_on_duty.' where id = '.$id.';';
echo $sql;
mysql_query($sql,$conn) or die(mysql_error());
echo '<script>alert("修改用户信息成功！");window.location="'.getHost().'/admin/personal-info-manage/index.php'.'";</script>';
